package com.hllxd;
/**
 * @author xiyong.lxy
 * @date 2021.07.12
 * @EnableScheduling
 */
import io.undertow.Undertow;
import io.undertow.UndertowOptions;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.undertow.UndertowBuilderCustomizer;
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.xnio.Options;

@Slf4j
@EnableAutoConfiguration
@SpringBootApplication
public class Application {

    private static final Integer TIMEOUT = 30*60*1000;

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    public UndertowServletWebServerFactory embeddedServletContainerFactory() {
        UndertowServletWebServerFactory factory =
            new UndertowServletWebServerFactory();
        factory.addBuilderCustomizers(new UndertowBuilderCustomizer() {
            @Override public void customize(Undertow.Builder builder) {
                builder.setSocketOption(UndertowOptions.IDLE_TIMEOUT, TIMEOUT)
                    .setSocketOption(Options.REUSE_ADDRESSES, true)
                    .setSocketOption(Options.READ_TIMEOUT, TIMEOUT)
                    .setSocketOption(Options.WRITE_TIMEOUT, TIMEOUT)
                    .setSocketOption(Options.KEEP_ALIVE, true);
            }
        });
        return factory;
    }

}
